package com.glodon.paas.activity.dao.domain;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Set;

import com.google.code.morphia.annotations.Entity;
import com.google.code.morphia.annotations.Id;
import com.google.code.morphia.annotations.NotSaved;
import com.google.code.morphia.annotations.Property;

/**
 * 活动实体类
 * 
 * @author a db.activity.ensureIndex({"userId":1, "rt":-1});
 */
@Entity(value = "activity2", noClassnameStored = true)
public class ActivityEntity {
    @NotSaved
    ActivityDefinitionEntity        defnition;      // 活动定义
    
    @Id
    private String                  id;             // uuid
    private String                  receiverId;         // 活动接受者:id
    // 活动来源
    private Integer                 appId;          // 活动来源:应用id
    private Integer                 moduleId;       // 活动来源:模块id
    private Long                    activityType;   // 活动类型:由各应用自定义

    // item
    private String                  itemId;         // 关联实体id，如文件，文件夹等
    private String                  itemName;       // 活动物体类型名：ccc.jpg等
    private String                  subItemId;      // 二级关联实体id等 ，如 项目 + 文件; 文件夹 + 文件;
    private String                  subItemName;    // 二级关联实体
    private String                  itemType;       // 关联实体名

    // 活动者
    private String                  actorId;        // 活动产生者ID:accountId
    private String                  actorName;      // 活动产生者名:displayName

    private String                  title;          // 动态标题，可以由其他属性组合
    private String                  content;        // 评论或回复内容，用户输入的
    // String contentType; // 内容类型：0:txt,1:json,2:xml,3:html
    @Property("display")
    private String                  displayContent;  // 输出内容，即模版转换后的内容
    @Property("tv")
    private int                     templateVersion; // 模版版本号
    // Boolean isComment; // 是否评论
    // Boolean isReply; // 是否回复
    @Property("pt")
    private Date                    publishTime;    // 客户端产生时间
    @Property("rt")
    private Date                    receiveTime;    // 服务端接受到动态数据的时间毫秒，也用于检索
    @Property("ct")
    private Date                    createTime;

    private String                  ext1;            // 扩展属性
    private String                  ext2;            // 扩展属性

    // 扩展属性
    private HashMap<String, Object> extension;
    // Boolean showThumbnails;
    // Boolean activityHasThumbnails;
    // Boolean activityViewable;
    // Boolean showDetailsLink;
    // Boolean showViewLink;
    // Boolean showEditSharingLink;
    // Boolean showAllThumbsLink;
    // Boolean showActivity;

    /**
     * 获取extension中以prefix开头的key集合，并按字符序列排序
     * @param prefix
     * @return
     */
    public List<String> extensionKeys(String prefix){
        List<String> list = new ArrayList<String>();
        Set<String> keys = extension.keySet();
        for(String key : keys){
            if(key.startsWith(prefix)){
                list.add(key);
            }
        }
        Collections.sort(list);
        return list;
    }
    /**
     * 从start开始，每次递增step，得到count个数字序列
     * @param prefix
     * @return
     */
    public List<Integer> numberArrays(int start, int step, Object scount){        
        Integer count = 0;
        try {
            count = Integer.parseInt(scount.toString());
        } catch (Exception e) {
            return new ArrayList<Integer>();
        }
        
        List<Integer> list = new ArrayList<Integer>();
        for(int i=0;i<count;i++){
            list.add(start);
            start += step;
        }
        return list;
    }
    

    public void putExtension(String key, Object value) {
        if (extension == null) {
            extension = new HashMap<String, Object>();
        }
        extension.put(key, value);
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Integer getAppId() {
        return appId;
    }

    public void setAppId(Integer appId) {
        this.appId = appId;
    }

    public Long getActivityType() {
        return activityType;
    }

    public void setActivityType(Long activityType) {
        this.activityType = activityType;
    }

    public String getItemId() {
        return itemId;
    }

    public void setItemId(String itemId) {
        this.itemId = itemId;
    }

    public String getItemName() {
        return itemName;
    }

    public void setItemName(String itemName) {
        this.itemName = itemName;
    }

    public String getActorId() {
        return actorId;
    }

    public void setActorId(String actorId) {
        this.actorId = actorId;
    }

    public String getActorName() {
        return actorName;
    }

    public void setActorName(String actorName) {
        this.actorName = actorName;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public ActivityDefinitionEntity getDefnition() {
        return defnition;
    }

    public void setDefnition(ActivityDefinitionEntity defnition) {
        this.defnition = defnition;
    }

    public HashMap<String, Object> getExtension() {
        return extension;
    }

    public void setExtension(HashMap<String, Object> extension) {
        this.extension = extension;
    }

    public String getItemType() {
        return itemType;
    }

    public void setItemType(String itemType) {
        this.itemType = itemType;
    }

    
    public String getDisplayContent() {
        return displayContent;
    }
    
    public void setDisplayContent(String displayContent) {
        this.displayContent = displayContent;
    }
    public int getTemplateVersion() {
        return templateVersion;
    }

    public void setTemplateVersion(int templateVersion) {
        this.templateVersion = templateVersion;
    }

    public Date getPublishTime() {
        return publishTime;
    }

    public void setPublishTime(Date publishTime) {
        this.publishTime = publishTime;
    }

    public String getSubItemId() {
        return subItemId;
    }

    public void setSubItemId(String subItemId) {
        this.subItemId = subItemId;
    }

    public String getSubItemName() {
        return subItemName;
    }

    public void setSubItemName(String subItemName) {
        this.subItemName = subItemName;
    }

    public Integer getModuleId() {
        return moduleId;
    }

    public Date getReceiveTime() {
        return receiveTime;
    }

    public void setReceiveTime(Date receiveTime) {
        this.receiveTime = receiveTime;
    }

    public String getReceiverId() {
        return receiverId;
    }
    
    public void setReceiverId(String receiverId) {
        this.receiverId = receiverId;
    }
    public void setModuleId(Integer moduleId) {
        this.moduleId = moduleId;
    }

    public String getExt1() {
        return ext1;
    }

    public void setExt1(String ext1) {
        this.ext1 = ext1;
    }

    public String getExt2() {
        return ext2;
    }

    public void setExt2(String ext2) {
        this.ext2 = ext2;
    }
}
